package com.ph.irp.base.measureunitgroup.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.measureunitgroup.service.PBaseMeasureUnitGroupService;
import com.ph.irp.model.PBaseMeasuregroup;

public class MeasureUnitGroupAction extends ActionSupport {
	private PBaseMeasuregroup measureGroupModel;
	private List<PBaseMeasuregroup> measureGroupList;
	private PBaseMeasureUnitGroupService measureGroupService;
	private Object[] rowlist;
	private String FORWARD = null;
	
	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public PBaseMeasuregroup getMeasureGroupModel() {
		return measureGroupModel;
	}

	public void setMeasureGroupModel(PBaseMeasuregroup measureGroupModel) {
		this.measureGroupModel = measureGroupModel;
	}

	public PBaseMeasureUnitGroupService getMeasureGroupService() {
		return measureGroupService;
	}

	public void setMeasureGroupService(
			PBaseMeasureUnitGroupService measureGroupService) {
		this.measureGroupService = measureGroupService;
	}

	public List<PBaseMeasuregroup> getMeasureGroupList() {
		return measureGroupList;
	}

	public void setMeasureGroupList(List<PBaseMeasuregroup> measureGroupList) {
		this.measureGroupList = measureGroupList;
	}
	
	public String getFORWARD() {
		return FORWARD;
	}

	public void setFORWARD(String forward) {
		FORWARD = forward;
	}
	
	/**
	 * 
	 * @return
	 * @throws Throwable
	 */
	
	
	public String addMeasureGroup() throws Throwable {
	
		this.measureGroupService.addMeasureGroup(measureGroupModel);
		
		FORWARD = "success";
		return FORWARD;
	}

	public String addInput() throws Exception {
		FORWARD = "success";
		return FORWARD;
	}

	public String deleteMeasureGroup()throws Throwable{
		
		this.measureGroupService.deleteMeasureGroup(rowlist);
		FORWARD = "success";
		return FORWARD;
	}

	public String showEditMeasureGroup() throws Throwable {
		measureGroupModel = this.measureGroupService.getMeasureGroupById(Integer.valueOf((String) rowlist[0]));
		FORWARD = "success";
		return FORWARD;
	}

	public String showMeasureGroupList() throws Throwable {
		measureGroupList = this.measureGroupService.getMeasureGroupAll();
		FORWARD = "success";
		return FORWARD;

	}
	

	public String searchMeasureGroup() throws Throwable {
		
		if(measureGroupModel == null){
			measureGroupList = this.measureGroupService.getMeasureGroupAll();
		}else{
			if(!measureGroupModel.getMeasureGroupCode().trim().equals("")&&!measureGroupModel.getMeasureGroupName().trim().equals("")){			
				measureGroupList = this.measureGroupService.getMeasureGroupByNameAndCode(measureGroupModel.getMeasureGroupName().trim(), measureGroupModel.getMeasureGroupCode().trim());				
			}
			else if(!measureGroupModel.getMeasureGroupCode().equals("")){
				
				measureGroupList = this.measureGroupService.getMeasureGroupByCode(measureGroupModel.getMeasureGroupCode().trim());		
			}
			else if(!measureGroupModel.getMeasureGroupName().equals("")){
				measureGroupList = this.measureGroupService.getMeasureGroupByName(measureGroupModel.getMeasureGroupName().trim());
			}
			else {
				measureGroupList = this.measureGroupService.getMeasureGroupAll();
				
			}
		}
		measureGroupModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	public String selectMeasureGroup() throws Throwable {
	
		if(measureGroupModel == null){
			measureGroupList = this.measureGroupService.getMeasureGroupAll();
		}else{
			if(!measureGroupModel.getMeasureGroupCode().trim().equals("")&&!measureGroupModel.getMeasureGroupName().trim().equals("")){			
				measureGroupList = this.measureGroupService.getMeasureGroupByNameAndCode(measureGroupModel.getMeasureGroupName().trim(), measureGroupModel.getMeasureGroupCode().trim());				
			}
			else if(!measureGroupModel.getMeasureGroupCode().equals("")){
				
				measureGroupList = this.measureGroupService.getMeasureGroupByCode(measureGroupModel.getMeasureGroupCode().trim());		
			}
			else if(!measureGroupModel.getMeasureGroupName().equals("")){
				measureGroupList = this.measureGroupService.getMeasureGroupByName(measureGroupModel.getMeasureGroupName().trim());
			}
			else {
				measureGroupList = this.measureGroupService.getMeasureGroupAll();
				
			}
		}
		measureGroupModel = null;
		FORWARD = "success";
		return FORWARD;

	}

	public String editMeasureGroup() throws Throwable {
	
		this.measureGroupService.updaeMeasureGroup(measureGroupModel);
		FORWARD = "success";
		return FORWARD;
	
	}




}
